/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
import org.orm.*;
import org.hibernate.Query;
import java.util.List;

public class PacienteDAO {
	public static Paciente loadPacienteByORMID(String dni_paciente) throws PersistentException {
		try {
			PersistentSession session = BasededatosPersistentManager.instance().getSession();
			return loadPacienteByORMID(session, dni_paciente);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Paciente getPacienteByORMID(String dni_paciente) throws PersistentException {
		try {
			PersistentSession session = BasededatosPersistentManager.instance().getSession();
			return getPacienteByORMID(session, dni_paciente);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Paciente loadPacienteByORMID(String dni_paciente, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = BasededatosPersistentManager.instance().getSession();
			return loadPacienteByORMID(session, dni_paciente, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Paciente getPacienteByORMID(String dni_paciente, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = BasededatosPersistentManager.instance().getSession();
			return getPacienteByORMID(session, dni_paciente, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Paciente loadPacienteByORMID(PersistentSession session, String dni_paciente) throws PersistentException {
		try {
			return (Paciente) session.load(Paciente.class, dni_paciente);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Paciente getPacienteByORMID(PersistentSession session, String dni_paciente) throws PersistentException {
		try {
			return (Paciente) session.get(Paciente.class, dni_paciente);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Paciente loadPacienteByORMID(PersistentSession session, String dni_paciente, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Paciente) session.load(Paciente.class, dni_paciente, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Paciente getPacienteByORMID(PersistentSession session, String dni_paciente, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Paciente) session.get(Paciente.class, dni_paciente, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Paciente[] listPacienteByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = BasededatosPersistentManager.instance().getSession();
			return listPacienteByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Paciente[] listPacienteByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = BasededatosPersistentManager.instance().getSession();
			return listPacienteByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Paciente[] listPacienteByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From Paciente as Paciente");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Paciente[]) list.toArray(new Paciente[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Paciente[] listPacienteByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From Paciente as Paciente");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Paciente[]) list.toArray(new Paciente[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Paciente loadPacienteByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = BasededatosPersistentManager.instance().getSession();
			return loadPacienteByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Paciente loadPacienteByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = BasededatosPersistentManager.instance().getSession();
			return loadPacienteByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Paciente loadPacienteByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Paciente[] pacientes = listPacienteByQuery(session, condition, orderBy);
		if (pacientes != null && pacientes.length > 0)
			return pacientes[0];
		else
			return null;
	}
	
	public static Paciente loadPacienteByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Paciente[] pacientes = listPacienteByQuery(session, condition, orderBy, lockMode);
		if (pacientes != null && pacientes.length > 0)
			return pacientes[0];
		else
			return null;
	}
	
	public static java.util.Iterator iteratePacienteByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = BasededatosPersistentManager.instance().getSession();
			return iteratePacienteByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePacienteByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = BasededatosPersistentManager.instance().getSession();
			return iteratePacienteByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePacienteByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From Paciente as Paciente");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePacienteByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From Paciente as Paciente");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Paciente createPaciente() {
		return new Paciente();
	}
	
	public static boolean save(Paciente paciente) throws PersistentException {
		try {
			BasededatosPersistentManager.instance().saveObject(paciente);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean delete(Paciente paciente) throws PersistentException {
		try {
			BasededatosPersistentManager.instance().deleteObject(paciente);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean deleteAndDissociate(Paciente paciente)throws PersistentException {
		try {
			Respuesta[] lRespuestas = paciente.respuesta.toArray();
			for(int i = 0; i < lRespuestas.length; i++) {
				lRespuestas[i].paciente.remove(paciente);
			}
			return delete(paciente);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean deleteAndDissociate(Paciente paciente, org.orm.PersistentSession session)throws PersistentException {
		try {
			Respuesta[] lRespuestas = paciente.respuesta.toArray();
			for(int i = 0; i < lRespuestas.length; i++) {
				lRespuestas[i].paciente.remove(paciente);
			}
			try {
				session.delete(paciente);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean refresh(Paciente paciente) throws PersistentException {
		try {
			BasededatosPersistentManager.instance().getSession().refresh(paciente);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean evict(Paciente paciente) throws PersistentException {
		try {
			BasededatosPersistentManager.instance().getSession().evict(paciente);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Paciente loadPacienteByCriteria(PacienteCriteria pacienteCriteria) {
		Paciente[] pacientes = listPacienteByCriteria(pacienteCriteria);
		if(pacientes == null || pacientes.length == 0) {
			return null;
		}
		return pacientes[0];
	}
	
	public static Paciente[] listPacienteByCriteria(PacienteCriteria pacienteCriteria) {
		return pacienteCriteria.listPaciente();
	}
}
